package com.example.administrator.game2048;

import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    private int score = 0;
    private TextView tvScore;
    private TextView topScore;
    private int currentTopScore;
    private static MainActivity mainActivity = null;

    public MainActivity() {

        mainActivity = this;
    }
    public static MainActivity getMainActivity() {

        return mainActivity;
    }

    public void onClick(View view){
        switch (view.getId()){
            case R.id.btnhelp:
                AlertDialog.Builder dialog2 = new AlertDialog.Builder(this);
                dialog2.setTitle("hey,guy！");
                dialog2.setMessage("这么简单的游戏你确定需要帮助？");
                dialog2.setNegativeButton("继续玩~", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                dialog2.show();
                break;
            case R.id.btnquit:
                AlertDialog.Builder dialog = new AlertDialog.Builder(this);
                dialog.setTitle("提示：");
                dialog.setMessage("你确定要离开吗？");
                dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        System.exit(0);
                    }
                });
                dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                dialog.show();
                break;
            case R.id.btnrestart:
                AlertDialog.Builder dialog3 = new AlertDialog.Builder(this);
                dialog3.setTitle("提示：");
                dialog3.setMessage("你确定重新开始吗？");
                dialog3.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                dialog3.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                dialog3.show();
                break;
                default:break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvScore = (TextView) findViewById(R.id.tv_currentscore);
        topScore = (TextView)findViewById(R.id.tv_topscore);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    //分数归零
    public void clearScore() {
        score = 0;
        showScore();
    }

    //添加分数的方法
    public void addScore(int s) {
        score += s;
        showScore();
        if (score > currentTopScore) {
            currentTopScore = score;
            TopScore ts = new TopScore(this);
            ts.setTopScore(currentTopScore);
            topScore.setText("" + currentTopScore);
        }
    }

    //使分数显示出来
    public void showScore() {

        tvScore.setText(score + " ");
    }

}
